(function(window, undefined) {
	function Food(map, option) {
		option = option || {};
		this.x = option.x || 0;
		this.y = option.y || 0;
		this.width = option.width || 20;
		this.height = option.height || 20;
		this.background = option.background || 'green';
		this.map = map;
		this.food = document.createElement('div');
	}
	Food.prototype = {
		constructor: Food,
		render: function() {
			let food = this.food;
			this.map.appendChild(food);
			this.randomXy();
			food.style.width = this.width + 'px';
			food.style.height = this.height + 'px';
			food.style.left = this.x * this.width + 'px';
			food.style.top = this.y * this.height + 'px';
			food.style.background = this.background;
			food.style.position = 'absolute';
		},
		randomXy: function() {
			this.x = Tools.getRandom(0, this.map.offsetWidth / this.width -1);
			this.y = Tools.getRandom(0, this.map.offsetHeight / this.height - 1);
		}
	}

	window.Food = Food;
})(window, undefined);		
// 在闭包结束的时候需要加上;否则会影响下一个闭包的调用
/* window和undefined的意义

	1. 传入参数时，可以在代码压缩的时候，对参数进行简化
	2. undefined可以在老版本中被重新赋值，传入undefined可以防止被重新定义，以至于代码出错

*/

